﻿@{
    Layout = null;
}

<form id="CodeRelateForm" role="form" onkeydown="if(event.keyCode==13){return false;}">

    <input type="hidden" id="Action" name="Action" value="1" />
    <div class="RowAlgnTop" id="codebatchs">
        <div class="col-xs-2 col-md-2 text-right">
            <span class="red-700">*</span>
            生码批次：
        </div>
        <div class="col-xs-10 col-md-10">
            @Html.DropDownList("CodeBatch", null, new
           {
               @class = "form-control",
               name = "CodeBatch",
               onchange = "$.MGJ.CodeRelate.onBatchChange()"
           })
        </div>
        <input type="hidden" id="HidCount" value="0" />
    </div>



    <div class="RowAlgnTop">
        <div class="col-xs-2 col-md-2 text-right">
            <span class="red-600">*</span>
            禁用方法：
        </div>
        <div class="col-xs-10 col-md-10">
            <label for="para" onclick="$.MGJ.CodeRelate.RelateTypeChange(0)">
                <input id="para" type="radio" name="RelateType" value="0" onchange="$.MGJ.CodeRelate.SetAllotType(0)" checked />&nbsp;按号段
            </label>
            <label for="all" onclick="$.MGJ.CodeRelate.RelateTypeChange(1)">
                <input id="all" type="radio" name="RelateType" value="1" style="margin-left:40px;" onchange="$.MGJ.CodeRelate.SetAllotType(1)" />&nbsp;整批
            </label>
            <label for="singleCode" onclick="$.MGJ.CodeRelate.RelateTypeChange(2)">
                <input id="singleCode" value="2" type="radio" name="RelateType" style="margin-left:40px;" onchange="$.MGJ.CodeRelate.SetAllotType(2)" />&nbsp;单号
            </label>

        </div>
    </div>

    <div class="RowAlgnTop" id="single_code" style="display:none">
        <div class="col-xs-2 col-md-2 text-right">
            <span class="red-600">*</span>
            单号：
        </div>
        <div class="col-xs-10 col-md-10">
            <textarea onkeypress="showCodeNum(this.value)" onchange="showCodeNum(this.value)" class="form-control" autocomplete="off" placeholder="格式说明：不能出现换行,以英文“,”结束。如下所示：
0070100000019969,0070100000019969,0070100000019969,0070100000019969," id="BoxCodes" name="SingleCodes" style="height: 148px;"></textarea>
            @*<textarea class="form-control" id="Wl_Code" name="Wl_Code" placeholder="请输入单号！"></textarea>*@
        </div>
    </div>


    <div id="SectionNum">
        <div class="RowAlgnTop">
            <div class=" col-xs-6 col-md-6">
                <div class="col-xs-4 col-md-4  text-right"><span class="red-600">*</span>起始码：</div>
                <div class="col-xs-8 col-md-8">
                    <input type="text" id="StartCode" name="StartCode" class="form-control" oninput="scanf_integral (event)" />
                </div>
            </div>
            <div class=" col-xs-6 col-md-6">
                <div class="col-xs-4 col-md-4  text-right"><span class="red-600">*</span>结束码：</div>
                <div class="col-xs-8 col-md-8">
                    <input type="text" id="EndCode" name="EndCode" class="form-control" oninput="scanf_integral (event)" />
                </div>
            </div>
        </div>
    </div>
    <div id="SectionNum2">
        <div class="RowAlgnTop form-group">
            <div class=" col-xs-6 col-md-6">
                <div class="col-xs-4 col-md-4  text-right">禁用码数量：</div>
                <div class="col-xs-8 col-md-8">
                    <input type="text" name="RelateCodeNums" id="RelateCodeNums1" class="form-control" readonly/>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    $(document).ready(function () {
        var _batchNum = $("#CodeBatch").find("option:selected").text();
        var wlcode = $("#BoxCodes").val();
        $.L.ajaxHandle({
            url: ACTION_URL("GetWholeBatchCount", "CodeManage"),
            type: "GET",
            data: { batchNo: _batchNum, wlcode: wlcode },
            success: function (r) {
                $("#HidCount").val(r);
            }
        })
    });

    function showCodeNum(val) {
        var reg=/^\d{16,18}$/;
        var arr = val.split(',');
        var Arr = [];
        $(arr).each(function (i, ele) {
            if (ele!='' && reg.test(ele))
            {
                Arr.push(ele);
            }
        })
        $('#RelateCodeNums3').val(Arr.length)
    }

    function CodeAmount() {
        var StartCode = $("#StartCode").val()
        var EndCode = $("#EndCode").val()

        if (StartCode != "" && EndCode != "") {
            $("#RelateCodeNums2").val(parseInt(EndCode) - parseInt(StartCode)+1)
        }
    }

    //起始码结束码
    function scanf_integral() {
        var StartCode = $("#StartCode").val();
        var EndCode = $("#EndCode").val();
        if (StartCode != '' && EndCode != '') {
            $("#RelateCodeNums1").val(parseInt(EndCode) - parseInt(StartCode) + 1)
        }
    }

    $(function () {
        $('#CodeRelateForm').bootstrapValidator({
            fields: {
                RelateType: {
                    validators: {
                        notEmpty: {
                            message: '禁用方法不能为空'
                        }
                    }
                },
                StartCode: {
                    validators: {
                        notEmpty: {
                            message: '起始码不能为空'
                        },
                        regexp: {
                            regexp: /^[1-9]*[1-9][0-9]*$/,
                            message: '起始码为正整数'
                        }
                    }
                },
                EndCode: {
                    validators: {
                        notEmpty: {
                            message: '结束码不能为空'
                        },
                        regexp: {
                            regexp: /^[1-9]*[1-9][0-9]*$/,
                            message: '结束码为正整数'
                        }
                    }
                },
                CodeBatch: {
                    validators: {
                        notEmpty: {
                            message: '生码批次不能为空'
                        }
                    }
                }
            }
        })
    })
</script>